
using System.Web.UI.HtmlControls;
using System;
using System.Configuration;
using System.Drawing;
using System.Data;
using System.Web.UI.WebControls;
using Microsoft.VisualBasic;
using System.Collections;
using System.Web.UI;
using System.Web;


using System.Xml;
using System.Text;
using System.IO;
using System.Globalization;
using System.Data.OleDb;
using System.Resources;
using System.Reflection;
//using System.Net.Dns;
using com.ddsc.common;


namespace smasb2b
{
	public class ServiceAgent : BasePage
	{
		
#region  Web Form 設計工具產生的程式碼
		
		//此為 Web Form 設計工具所需的呼叫。
		[System.Diagnostics.DebuggerStepThrough()]private void InitializeComponent()
		{
			
		}
		
		//注意: 下列預留位置宣告是 Web Form 設計工具需要的項目。
		//請勿刪除或移動它。
		private System.Object designerPlaceholderDeclaration;
		
		private void Page_Init(System.Object sender, System.EventArgs e)
		{
			//CODEGEN: 此為 Web Form 設計工具所需的方法呼叫
			//請勿使用程式碼編輯器進行修改。
			InitializeComponent();
		}
		
#endregion
		
		private void Page_Load(System.Object sender, System.EventArgs e)
		{
			//在這裡放置使用者程式碼以初始化網頁
			object objProgram = null;
			
			try
			{
				string innerXML = "";
				
				//1. 設定回應資料型態
				Response.ContentType = "text/xml; charset=utf-8";
				
				//檢核是否由本系統發出的Request
				//If System.Net.Dns.GetHostByAddress(Request.UrlReferrer.Host).HostName.ToUpper <> System.Net.Dns.GetHostByName(Server.MachineName).HostName.ToUpper Then
				//    Return
				//End If
				
				//2. 取得 client 端傳送資料 (xml format)
				StreamReader sr = new StreamReader(Request.InputStream, System.Text.Encoding.UTF8);
				string questXML = sr.ReadToEnd();
				sr.Close();
				
				//3. 畫面每頁顯筆數
				string strPageSize = "";
				XmlDocument xmldoc = new XmlDocument();
				XmlAttribute xmlatt = default(XmlAttribute);
				xmldoc.LoadXml(questXML);
				string strClassName = xmldoc.SelectSingleNode("//form").Attributes["id"].Value;
				string strMethodName = xmldoc.SelectSingleNode("//form").Attributes["method"].Value;
				string TableName = xmldoc.SelectSingleNode("//command").Attributes["id"].Value;
				
				xmlatt = xmldoc.SelectSingleNode("//command").Attributes["pagesize"];
				
				string xmlaction = xmldoc.SelectSingleNode("//command").Attributes["action"].Value;
				if (xmlatt == null)
				{
					if (ConfigurationSettings.AppSettings["pagesize"] == null)
					{
						strPageSize = "20";
					}
					else
					{
						strPageSize = ConfigurationSettings.AppSettings["pagesize"];
					}
				}
				else
				{
					strPageSize = xmlatt.Value;
				}
				//4. 將 questXML == > ddscDataSet
				
				ddscDataSet ddscDs = default(ddscDataSet);
				//5 dynamic load class.method 以下造成處理序Lock的原因
				//Dim appPath As String = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(8)
				//Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFile(appPath)
				
				
				//5.2 動態元件建構子的參數
				//Dim objArgs(5) As Object
				//objProgram = Activator.CreateInstance(type_CustomerType, objArgs)
				object[] objMethodArgs = new object[1];
				DataTable dt = default(DataTable);
				DataSet ds = default(DataSet);
				switch (xmlaction.ToLower())
				{
					case "sel":
						ddscDs = new ddscDataSet(questXML, int.Parse(strPageSize));
						objMethodArgs[0] = ddscDs;
						break;
					case "xml":
						dt = TransformDetailDataTable(questXML, TableName);
						objMethodArgs[0] = dt;
						break;
					case "xml-ds":
						ds = TransformDataSet(questXML);
						objMethodArgs[0] = ds;
						break;
				}
				
				// 5.1 動態元件名稱 ()
				string strNamespace = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
				Type type_CustomerType = System.Reflection.Assembly.GetExecutingAssembly().GetType(strNamespace + "." + strClassName);
				objProgram = Activator.CreateInstance(type_CustomerType);
				
				// 5.2 method 名稱
				MethodInfo medCustomMethod = type_CustomerType.GetMethod(strMethodName);
				object objReturnValue = medCustomMethod.Invoke(objProgram, objMethodArgs);
				
				if (objReturnValue.GetType().Name == "DataSet")
				{
					DataSet dsReturn = (DataSet) objReturnValue;
					//6. return value == > response xml
					innerXML = ResponseXML(dsReturn, strPageSize);
				}
				else
				{
					//直接回傳XML String
					innerXML = System.Convert.ToString(objReturnValue);
				}
				//7 Response.Write(innerXML)
				Response.Write(innerXML);
				
			}
			catch (XmlException ev)
			{
				Response.StatusCode = 999;
				Response.Write(ev.Message);
				Response.Write(ev.StackTrace);
				//ResponseXML(ev)
			}
			catch (Exception ex)
			{
				Response.StatusCode = 999;
				Response.Write(ex.Message);
				Response.Write(ex.StackTrace);
				//ResponseXML(ex)
			}
			finally
			{
				objProgram = null;
				this.Dispose();
			}
		}
		//Creator : Titan Xei
		//Update Date : 2005/03/23
		//Context : 提供XML轉換成DataTable
		public DataTable TransformDetailDataTable(string XMLString, string TableName)
		{
			//將XML 載入
			XmlDocument XmlDoc = new XmlDocument();
			XmlDoc.LoadXml(XMLString);
			string XPath = "//parameter";
			XmlNodeList XmlList = XmlDoc.SelectNodes(XPath);
			XmlNode NodeItem = default(XmlNode);
			DataTable dt = new DataTable(TableName);
			int i = 0;
			DataRow dr = default(DataRow);
			try
			{
				foreach (XmlNode tempLoopVar_NodeItem in XmlList)
				{
					NodeItem = tempLoopVar_NodeItem;
					dr = dt.NewRow();
					//建立column
					for (i = 0; i <= NodeItem.Attributes.Count - 1; i++)
					{
						XmlAttribute xmlatt = NodeItem.Attributes[i];
						if (NodeItem.Attributes.Count != dt.Columns.Count)
						{
							dt.Columns.Add(new DataColumn(xmlatt.Name));
						}
						dr[i] = xmlatt.Value;
					}
					dt.Rows.Add(dr);
				}
			}
			catch (Exception ex)
			{
				throw (ex);
			}
			return dt;
		}
		
		public DataTable TransformMastDataTable(string XMLString, string TableName)
		{
			//將XML 載入
			XmlDocument XmlDoc = new XmlDocument();
			XmlDoc.LoadXml(XMLString);
			string XPath = "//parameter";
			XmlNodeList XmlList = XmlDoc.SelectNodes(XPath);
			XmlNode NodeItem = default(XmlNode);
			DataTable dt = new DataTable(TableName);
			int i = 0;
			DataRow dr = default(DataRow);
			try
			{
				dr = dt.NewRow();
				foreach (XmlNode tempLoopVar_NodeItem in XmlList)
				{
					NodeItem = tempLoopVar_NodeItem;
					dt.Columns.Add(new DataColumn(NodeItem.Attributes.GetNamedItem("id").Value));
					dr[i] = NodeItem.InnerText;
					i++;
				}
				dt.Rows.Add(dr);
			}
			catch (Exception ex)
			{
				throw (ex);
			}
			return dt;
		}
		
		//Creator : Titan Xei
		//Update Date : 2005/03/23
		//Context : 提供XML轉換成DataSet
		public DataSet TransformDataSet(string XMLString)
		{
			DataSet ds = new DataSet();
			ds.DataSetName = "DataSet";
			XmlDocument XmlDoc = new XmlDocument();
			XmlDoc.LoadXml(XMLString);
			try
			{
				string XPath = "//command";
				XmlNode XmlNode1 = XmlDoc.SelectNodes(XPath).Item(0);
				XmlNode XmlNode2 = XmlDoc.SelectNodes(XPath).Item(1);
				
				ds.Tables.Add(TransformMastDataTable(XmlNode1.OuterXml, XmlNode1.Attributes.GetNamedItem("id").Value));
				ds.Tables.Add(TransformDetailDataTable(XmlNode2.OuterXml, XmlNode2.Attributes.GetNamedItem("id").Value));
			}
			catch (Exception ex)
			{
				throw (ex);
			}
			
			return ds;
			
		}
		
		
		//Creator : Titan Xei
		//Update Date : 2005/03/17
		//Context : 提供Clinet 取得AP相關資料
		public string ServerInfoByClinetMethod(ddscDataSet p_ddscDt)
		{
			DataSet ds = p_ddscDt.getDataSet();
			string dataType = System.Convert.ToString(ds.Tables[0].Rows[1]["dataType"]);
			string DataFormat = System.Convert.ToString(ds.Tables[0].Rows[1]["DataFormat"]);
			string ReturnValue = "";
			string ResponseXML = "";
			try
			{
				//取得clinet 需要的資料
				switch (dataType.ToLower())
				{
					case "date":
						ReturnValue = DateTime.Today.ToString(DataFormat);
						break;
					case "time":
						ReturnValue = DateTime.Now.ToString(DataFormat);
						break;
					case "servername":
						ReturnValue = Server.MachineName;
						break;
					case "config": //DataFormat 為Webconfig's Key Value
						ReturnValue = System.Configuration.ConfigurationSettings.AppSettings[DataFormat];
						break;
					default:
						ReturnValue = "";
						break;
				}
				//回傳組合XML
				ResponseXML = "<Response>" + 
					"<items>" + ReturnValue + "</items>" + 
					"</Response>";
			}
			catch (Exception)
			{
				ResponseXML = "<Response><items></items></Response>";
			}
			
			return ResponseXML;
		}
		
		
		//Creator : Titan Xei
		//Update Date : 2006/02/17
		//Context : 提供Clinet 取得錯誤訊息資料
		public string GetLanguageMessage(ddscDataSet p_ddscDt)
		{
			DataSet ds = p_ddscDt.getDataSet();
			string MSGID = System.Convert.ToString(ds.Tables[0].Rows[1]["MSGID"]);
			ResourceManager rm = new ResourceManager(System.Convert.ToString("smasb2b." + System.Convert.ToString(Session["langauage"])), System.Reflection.Assembly.GetExecutingAssembly());
			string ReturnValue = "";
			string ResponseXML = "";
			try
			{
				ReturnValue = rm.GetString(MSGID);
				//回傳組合XML
				ResponseXML = "" + 
					"<Response>" + 
					"<items>" + ReturnValue + "</items>" + 
					"</Response>";
			}
			catch (Exception)
			{
				ResponseXML = "<Response><items></items></Response>";
			}
			
			return ResponseXML;
		}
		
		//Private Function QueryDataAdapter(ByVal xmlDoc As XmlDocument)
		//    Dim cn As OleDbConnection = New OleDbConnection(ConfigurationSettings.AppSettings("dbsvr"))
		//    Dim strPageSize As String = ConfigurationSettings.AppSettings("pagesize")
		//    Dim InnerXMLItemBuilder As StringBuilder = New StringBuilder
		//    Dim InnerXMLBuilder As StringBuilder = New StringBuilder
		//    Dim da As OleDbDataAdapter
		//    Dim ds As DataSet
		//    Dim i As Integer, j As Integer
		//    Try
		//        Dim strPageIndex As String = xmlDoc.DocumentElement.Attributes("pageindex").Value
		//        da = New OleDbDataAdapter(GetSqlCommandText(xmlDoc), cn)
		//        ds = New DataSet
		
		//        'da.Fill(ds, "dbTable")
		//        da.Fill(ds, strPageIndex * strPageSize - strPageSize, strPageSize, "dbTable")
		//        Dim FunctionHandler As FunctionHandler = New FunctionHandler
		//        Dim rm As ResourceManager = LanguageManager("zh-tw")
		//        Dim dt As DataTable = ds.Tables("dbTable")
		//        InnerXMLBuilder.Append("<Response>")
		//        InnerXMLBuilder.Append("<Messages>")
		//        InnerXMLBuilder.Append("<Exception>null</Exception>")
		//        InnerXMLBuilder.Append("<Message>資料讀取完成</Message>")
		//        InnerXMLBuilder.Append("</Messages>")
		//        InnerXMLItemBuilder.Append("<Data count='" + CStr(dt.Rows.Count) + "'>")
		//        If dt.Rows.Count > 0 Then
		//            InnerXMLBuilder.Append("<Columns>")
		//            For j = 0 To dt.Columns.Count - 1
		//                InnerXMLBuilder.Append("<Column id='" + dt.Columns(j).ColumnName + "' name='" + rm.GetString(dt.Columns(j).ColumnName.ToUpper) + "'></Column>")
		//            Next
		//            InnerXMLBuilder.Append("</Columns>")
		//        End If
		//        For i = 0 To dt.Rows.Count - 1
		//            InnerXMLItemBuilder.Append("<Items>")
		//            For j = 0 To dt.Columns.Count - 1
		//                InnerXMLItemBuilder.Append("<Item>" + dt.Rows(i).Item(j) + "</Item>")
		//            Next
		
		//            InnerXMLItemBuilder.Append("</Items>")
		//        Next
		//        InnerXMLBuilder.Append(InnerXMLItemBuilder.ToString())
		//        InnerXMLBuilder.Append("</Data>")
		//        InnerXMLBuilder.Append("</Response>")
		//        QueryDataAdapter = InnerXMLBuilder.ToString()
		
		//    Catch ev As OleDbException
		//        Throw New Exception("QueryDataAdapter() :" + ev.Message)
		//    Catch ew As NullReferenceException
		//        Throw ew
		//    Catch ex As Exception
		//        Throw ex
		//    Finally
		//        da.Dispose()
		//        ds.Dispose()
		//        cn.Close()
		//    End Try
		//End Function
		
		//Private Function QueryDataReader(ByVal xmlDoc As XmlDocument)
		//    Dim cn As OleDbConnection = New OleDbConnection(ConfigurationSettings.AppSettings("dbsvr"))
		//    Dim InnerXMLBuilder As StringBuilder = New StringBuilder
		//    Dim i As Integer, j As Integer, ArrOfValue As Array, innerText As String, refText As String
		//    Try
		//        Dim Command As OleDbCommand = New OleDbCommand(GetSqlCommandText(xmlDoc), cn)
		//        cn.Open()
		//        Dim DataReader As OleDbDataReader = Command.ExecuteReader()
		
		//        '組合查詢資料庫結果組合成XML格式
		//        InnerXMLBuilder.Append("<Response>")
		//        InnerXMLBuilder.Append("<Messages>")
		//        InnerXMLBuilder.Append("<Exception>null</Exception>")
		//        InnerXMLBuilder.Append("<Message>資料讀取完成</Message>")
		//        InnerXMLBuilder.Append("</Messages>")
		//        InnerXMLBuilder.Append("<Data>")
		//        While (DataReader.Read)
		//            InnerXMLBuilder.Append("<items>")
		//            For i = 0 To DataReader.FieldCount - 1
		//                If Not IsDBNull(DataReader(i)) Then
		//                    If (Split(DataReader(i), ";").Length = 2) Then
		//                        refText = Split(DataReader(i), ";").GetValue(1)
		//                        innerText = Split(DataReader(i), ";").GetValue(0)
		//                        InnerXMLBuilder.Append("<item id='" + DataReader.GetName(i) + "'  ref='" + refText + "'>" + innerText + "</item>")
		//                    Else
		//                        innerText = Split(DataReader(i), ";").GetValue(0)
		//                        InnerXMLBuilder.Append("<item id='" + DataReader.GetName(i) + "'>" + innerText + "</item>")
		//                    End If
		//                Else
		//                    InnerXMLBuilder.Append("<item id='" + DataReader.GetName(i) + "'></item>")
		//                End If
		//            Next
		//            InnerXMLBuilder.Append("</items>")
		//        End While
		
		
		//        Command.Dispose()
		//        DataReader.Close()
		//        cn.Close()
		
		//        InnerXMLBuilder.Append("</Data>")
		//        InnerXMLBuilder.Append("</Response>")
		//        '回傳XML資料格式
		//        QueryDataReader = InnerXMLBuilder.ToString()
		
		//    Catch ev As OleDbException
		//        Throw New Exception("QueryDataReader() :" + ev.Message)
		//    Catch ex As Exception
		//        Throw ex
		//    End Try
		//End Function
		
		//Private Function GetSqlCommandText(ByVal xmlDoc As XmlDocument)
		
		//    Dim filterid As String, filteroper As String, filtervalue As String, filtertype As String, ConditionalText As String
		//    Dim i As Integer, j As Integer, SelectCommandText As String
		
		//    Try
		//        Dim strSqlCommandID As String = xmlDoc.DocumentElement.Attributes("id").Value
		//        Dim strSrot As String = xmlDoc.DocumentElement.Attributes("sort").Value
		
		//        Dim NodesList As XmlNodeList = xmlDoc.DocumentElement.SelectNodes("//Parameter")
		
		//        If (strSqlCommandID = "Query_CustemMultiItem") Then
		//            SelectCommandText = "SELECT CustomerID,ContactName,ContactTitle,Address,City,Region FROM Customers"
		//        Else
		//            SelectCommandText = "SELECT (CustomerID + ';' + CompanyName) AS CustomerID,(CompanyName + ';' + ContactName) AS CompanyName ,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax  FROM Customers"
		//        End If
		
		//        '組合查詢條件
		//        For i = 0 To NodesList.Count - 1
		//            filterid = NodesList.Item(i).Attributes("id").Value
		//            filteroper = NodesList.Item(i).Attributes("operator").Value.ToLower()
		//            filtervalue = NodesList.Item(i).InnerText.Replace("'", "''").Trim()
		//            filtertype = NodesList.Item(i).Attributes("type").Value
		//            If filtervalue <> "" Then
		//                Select Case filteroper
		//                    Case "between"
		//                        Select Case filtertype
		//                            Case "text"
		//                                ConditionalText += String.Format(" {0} BETWEEN '{1}' AND '{2}' {3} ", filterid, NodesList.Item(i).FirstChild.InnerText, NodesList.Item(i).LastChild.InnerText, "AND")
		//                            Case "number"
		//                                ConditionalText += String.Format(" {0} BETWEEN {1} AND {2} {3} ", filterid, NodesList.Item(i).FirstChild.InnerText, NodesList.Item(i).LastChild.InnerText, "AND")
		//                        End Select
		//                    Case Else
		//                        Select Case filtertype
		//                            Case "text"
		//                                ConditionalText += String.Format(" {0} {1} '{2}' {3}", filterid, filteroper, filtervalue, "AND")
		//                            Case "number"
		//                                ConditionalText += String.Format(" {0} {1} {2} {3}", filterid, filteroper, filtervalue, "AND")
		//                        End Select
		//                End Select
		
		//            End If
		//        Next
		
		//        If ConditionalText <> "" Then
		//            ConditionalText = " WHERE " & left(ConditionalText, Len(ConditionalText) - 4)
		//        End If
		//        If strSrot <> "" Then
		//            ConditionalText = String.Format(ConditionalText + " ORDER BY {0} ", strSrot)
		//        End If
		//        '回傳資料庫命令語法
		//        GetSqlCommandText = SelectCommandText + ConditionalText
		
		//    Catch ew As IndexOutOfRangeException
		//        Throw New Exception("GetSqlCommandText() :" + ew.Message)
		//    Catch ev As NullReferenceException
		//        Throw New Exception("GetSqlCommandText() :執行XML 不支援設定的屬性," + ev.Message)
		//    Catch ex As Exception
		//        Throw New Exception("GetSqlCommandText() :" + ex.Message)
		//    End Try
		//End Function
		
		public string ResponseXML(DataSet p_DataSet, string p_pagesize)
		{
			string returnValue = "";
			
			StringBuilder InnerXMLBuilder = new StringBuilder();
			
			try
			{
				
				//組合查詢資料庫結果組合成XML格式 (多國語言碼)
				FunctionHandler FunctionHandler = new FunctionHandler();
				
				//設定多國語言的編碼
				//Dim rm As ResourceManager = LanguageManager(CType(LoginUser(), Employee).UseLanguage)
				
				
				InnerXMLBuilder.Append("<Response>");
				
				// 取得交易結果的 DataTable
				DataTable info = p_DataSet.Tables["info"];
				
				short info_index = 0;
				for (info_index = 0; info_index <= info.Rows.Count - 1; info_index++)
				{
					
					StringBuilder InnerXMLItemBuilder = new StringBuilder();
					DataTable dt = p_DataSet.Tables[(info.Rows[info_index]["TransResult"]).ToString()];
					// 交易結果訊息
					InnerXMLBuilder.Append("<info id=\'" + (info.Rows[info_index]["TransResult"]).ToString() + "\' pagesize=\'" + p_pagesize + "\'>");
					InnerXMLBuilder.Append("<TransResult>" + (info.Rows[info_index]["TransResult"]).ToString() + "</TransResult>");
					InnerXMLBuilder.Append("<ReturnCode>" + (info.Rows[info_index]["ReturnCode"]).ToString() + "</ReturnCode>");
					InnerXMLBuilder.Append("<RecordsAffected>" + (info.Rows[info_index]["RecordsAffected"]).ToString() + "</RecordsAffected>");
					InnerXMLBuilder.Append("<Message>" + (info.Rows[info_index]["Message"]).ToString() + "</Message>");
					InnerXMLBuilder.Append("<RowCount>" + (info.Rows[info_index]["RowCount"]).ToString() + "</RowCount>");
					
					// 加入查詢位置
					if (!(info.Columns["Position"] == null))
					{
						InnerXMLBuilder.Append("<Position>" + (info.Rows[info_index]["Position"]).ToString() + "</Position>");
					}
					InnerXMLBuilder.Append("</info>");
					
					// 判斷回傳的 dataset 中的 table 數目, 若大於 count - 1 > 0, 則表示有回傳的資料
					if (p_DataSet.Tables.Count - 1 > 0)
					{
						int i = 0;
						int j = 0;
						if (dt.Rows.Count > 0)
						{
							// 欄位名稱 (轉多國語言碼)
							InnerXMLBuilder.Append("<" + (info.Rows[info_index]["TransResult"]).ToString() + "_Columns>");
							for (j = 0; j <= dt.Columns.Count - 1; j++)
							{
								InnerXMLBuilder.Append("<Column id=\'" + dt.Columns[j].ColumnName + "\'></Column>"); //Debug by titan for "被mark造成xml無欄位編號則取不到資料
							}
							InnerXMLBuilder.Append("</" + (info.Rows[info_index]["TransResult"]).ToString() + "_Columns>");
						}
						
						InnerXMLItemBuilder.Append("<" + (info.Rows[info_index]["TransResult"]).ToString() + "_Data count=\'" + (dt.Rows.Count).ToString() + "\'>");
						for (i = 0; i <= dt.Rows.Count - 1; i++)
						{
							// row 資料
							InnerXMLItemBuilder.Append("<Items>");
							for (j = 0; j <= dt.Columns.Count - 1; j++)
							{
								//InnerXMLItemBuilder.Append("<Item>" + dt.Rows(i).Item(j) + "</Item>") modify by Mirth 2005/1/6
								string strData = System.Convert.ToString(dt.Rows[i][j].ToString());
								//取代XML之保留字
								strData = ToNormalString(strData);
								InnerXMLItemBuilder.Append("<Item>" + strData + "</Item>");
							}
							
							InnerXMLItemBuilder.Append("</Items>");
						}
						
						InnerXMLBuilder.Append(InnerXMLItemBuilder.ToString());
						InnerXMLBuilder.Append("</" + (info.Rows[info_index]["TransResult"]).ToString() + "_Data>");
					}
				}
				
				
				InnerXMLBuilder.Append("</Response>");
				
				returnValue = InnerXMLBuilder.ToString();
			}
			catch (Exception ex)
			{
				InnerXMLBuilder.Append("<Response>");
				InnerXMLBuilder.Append("<info>");
				InnerXMLBuilder.Append("<Exception>" + ex.StackTrace + "</Exception>");
				InnerXMLBuilder.Append("<Message>" + ex.Message + "</info>");
				InnerXMLBuilder.Append("</Messages>");
				InnerXMLBuilder.Append("</Response>");
				
				returnValue = InnerXMLBuilder.ToString();
			}
			
			return returnValue;
		}
		
		public void ResponseXML(Exception Ex)
		{
			StringBuilder InnerXMLBuilder = new StringBuilder();
			//組合查詢資料庫結果組合成XML格式
			InnerXMLBuilder.Append("<Response>");
			InnerXMLBuilder.Append("<info>");
			InnerXMLBuilder.Append("<Exception>" + Ex.StackTrace + "</Exception>");
			InnerXMLBuilder.Append("<Message>" + Ex.StackTrace + "</Message>");
			InnerXMLBuilder.Append("</info>");
			InnerXMLBuilder.Append("</Response>");
			Response.Write(InnerXMLBuilder.ToString());
			InnerXMLBuilder.Remove(0, InnerXMLBuilder.Length);
		}
		
		public string ToNormalString(string original)
		{
			string strOriginal = original;
			strOriginal = strOriginal.Replace("&", "&amp;");
			strOriginal = strOriginal.Replace(">", "&gt;");
			strOriginal = strOriginal.Replace("<", "&lt;");
			return strOriginal;
		}
		
	}
	
	
}
